GM.BlockTypes = {
Barricade = { model = "models/hunter/blocks/cube05x05x05.mdl" }
}

local cur_block = ""
local last_block_angle = Angle(0,0,0)
local last_block_pos = Vector(0,0,0)
local real_block_angle = Angle(0,0,0)
local real_block_pos = Vector(0,0,0)
local is_creating_block = false
function GM:SetBlock( str )
	if cur_block == str then
		GAMEMODE:CancelBlockCreation()
		return
	end
	
	cur_block = str
	
	if GAMEMODE.BlockTypes[ str ] then
		LocalPlayer().Creator:SetModel( GAMEMODE.BlockTypes[ str ].model )
		is_creating_block = true
	else
		LocalPlayer().Creator:SetNoDraw( true )
		is_creating_block = false
	end
end

function GM:CreateBlock()
	-- Yes, I'm very optimistic.
	-- But having accurate positions and angles when a block is created is part of the fun.
	-- Fun > security.
	RunConsoleCommand( "create_block", cur_block, real_block_pos.x, real_block_pos.y, real_block_pos.z, real_block_angle.p, real_block_angle.y, real_block_angle.r, LocalPlayer():GetSyncVar( "optimistic" ) )
end

function GM:DrawBlock( block, pos, ang )

	if not block then return end
	if not GAMEMODE.BlockTypes[ cur_block ] then return end

	last_block_angle = LerpAngle( 0.15, last_block_angle, ang )
	last_block_pos = LerpVector( 0.5, last_block_pos, pos )
	real_block_angle = ang
	real_block_pos = pos
	
	--block:SetModel("models/hunter/blocks/cube05x05x05.mdl")
	block:SetAngles( last_block_angle )
	block:SetPos( last_block_pos )
	
	render.SuppressEngineLighting( true )
	block:DrawModel()
	render.SuppressEngineLighting( false )
	
	render.SetBlend(0.50)
	block:DrawModel()
	render.SetBlend(1)
	
end

function GM:CancelBlockCreation()
	cur_block = ""
	LocalPlayer().Creator:SetNoDraw( true )
	is_creating_block = false
end

function GM:IsCreatingBlock()
	return is_creating_block
end
